package com.acme.bankapp.server;

import com.acme.bankapp.domain.Bank;

import java.io.*;

/**
 * Created by Java Student on 11/19/2014.
 */
public class BankServer {

    private OutputStream outputStream;
    private InputStream inputStream;

    public OutputStream getOutputStream() {
        return outputStream;
    }

    public InputStream getInputStream() {
        return inputStream;
    }

    public void startServer(Bank bank) {
        int portNumber = 6669;
        while (true) {
            try {
                BankServerProxy bankServerProxy = new BankServerProxy(new BankServerTransport(portNumber));
                String cmd = "";
                while (!"exit".equals(cmd)) {
                    cmd = bankServerProxy.loadCommand();
                    bankServerProxy.processCommand(bank, cmd);
                }
                bankServerProxy.getBankServerTransport().getSocket().close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }

}
